﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TWVA09
    {

        public TWVA09()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVAFARBEN();
            DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVF = dwMaster;
            if (dwMaster != null)
            {
                FARBGRP = dwMaster["VAFFARBGRP"].ToString();
                PRART = dwMaster["VAAARTST"].ToString().PadRight(1) + TMV.VAFPART + TMV.VAFPVAR.PadRight(3) + TMV.VAFFFARBE + TMV.VAFBESCHICH + TMV.VAFDESS + TMV.VAFCOLORIT + TMV.VAFPGROE;
                KEY = dwMaster["VAFKOLL"].ToString() + dwMaster["VAFART"].ToString() + dwMaster["VAFFARBE"].ToString();
                TXTISIND = KEY.PadRight(60);
            }
            else
            {
                PRART = "";
                KEY = "";
                TXTISIND = "";
            }
        }
        public override void OnEXAUFChg(string value)
        {
            try
            {
                TBMain.Clear();
                if (value.Length < 29)
                    return;
                dwData = TBMain.NewRow();
                dwData["VAFMANDANT"] = app.Mandant;
                dwData["VAFKOLL"] = value.Substring(0, 5);
                dwData["VAFART"] = value.Substring(5, 24);
                SResult = TMV.QVAF_1(dwData);
                MergeData(SResult, true);
                base.OnEXAUFChg(value);
                if (!IsAuto)
                    return;
                if (Counts > 0)
                    return;

                if (FARBE.Trim().Length < 1)
                {
                    FARBE = " ".PadRight(10);
                    //throw new Exception("请先输入色号");
                }
                dwData = TBMain.NewRow();
                TMV.SetUpNewRow(ref dwData);
                dwData["VAFKOLL"] = value.Substring(0, 5);
                dwData["VAFART"] = value.Substring(5, 24);
                dwData["VAFFARBE"] = FARBE.PadRight(10);
                dwData["VAFFFARBE"] = FARBE.PadRight(10);
                Insert(dwData);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

    }
}
